import request from '@/utils/request';
const getChatList = async () => {
  const url = $globalRequestUrl({
    url: '/user/chat',
  });
  return await request({
    url,
    method: 'get',
  })
};
const getChatDetail = async (chatId) => {
  const url = $globalRequestUrl({
    url: `/user/chat/detail?id=${chatId}`,
  });
  return await request({
    url,
    method: 'get',
  })
}

// 发起聊天
const createChat = async (data) => {
  const url = $globalRequestUrl({
    url: '/user/chat/create',
  });
  return await request({
    url,
    method: 'post',
    data
  })
}
// const postChatMessage = async (data) => {
//   const url = $globalRequestUrl({
//     url: '/user/chat/generate',
//   });
//   return await request({
//     url,
//     method: 'post',
//     data
//   })
// }
// 2025-04-03 新聊天接口
const postChatMessage = async (data) => {
  // let url = '/user/chat/new/generate'
  // if (baseUrl) {
  //   url = `${baseUrl}api/user/chat/new/generate`
  // } else {
  //   url = $globalRequestUrl({
  //     url: '/user/chat/new/generate',
  //   });
  // }
  const url = $globalRequestUrl({
    url: '/user/chat/new/generate',
  });
  console.log("🚀 ~ postChatMessage ~ url:", url)
  return await request({
    url,
    method: 'post',
    data
  })
}
// 保存聊天记录
const saveChatMessage = async (data) => {
  const url = $globalRequestUrl({
    url: '/user/chat/record/save',
  });
  return await request({
    url,
    method: 'post',
    data
  })
}
// 编辑聊天记录
const editChatMessage = async (data) => {
  const url = $globalRequestUrl({
    url: '/user/chat/record/edit',
  });
  return await request({
    url,
    method: 'post',
    data
  })
}
// 删除聊天记录
const deleteChatMessage = async (data) => {
  const url = $globalRequestUrl({
    url: '/user/chat/record/delete',
  });
  return await request({
    url,
    method: 'post',
    data
  })
}
// 批量删除聊天记录
const batchDeleteChatMessage = async (data) => {
  const url = $globalRequestUrl({
    url: '/user/chat/record/batch_delete',
  });
  return await request({
    url,
    method: 'post',
    data
  })
}
const getPersonChatList = async () => {
  const url = $globalRequestUrl({
    url: '/user/personas',
  });
  return await request({
    url,
    method: 'get',
  })
}
const postCreateRole = async (data) => {
  const url = $globalRequestUrl({
    url: '/user/personas/create',
  });
  return await request({
    url,
    method: 'post',
    data
  })
}
// 修改我的角色
const postEditRole = async (data) => {
  const url = $globalRequestUrl({
    url: '/user/personas/edit',
  });
  return await request({
    url,
    method: 'post',
    data
  })
}
// 获取角色详情
const getRoleDetails = async (id) => {
  const url = $globalRequestUrl({
    url: `/user/personas/detail?id=${id}`,
  });
  return await request({
    url,
    method: 'get',
  })
}

const handleSetDefaultRole = async (data) => {
  const url = $globalRequestUrl({
    url: '/user/personas/default',
  });
  return await request({
    url,
    method: 'post',
    data
  })
}
const getTemplateList = async () => {
  const url = $globalRequestUrl({
    url: '/user/template',
  });
  return await request({
    url,
    method: 'get',
  })
}
const setDefalutTemplate = async (data) => {
  const url = $globalRequestUrl({
    url: '/user/template/default',
  });
  return await request({
    url,
    method: 'post',
    data
  })
}
const deleteRole = async (data) => {
  const url = $globalRequestUrl({
    url: '/user/personas/delete',
  });
  return await request({
    url,
    method: 'post',
    data
  })
}
const deleteChat = async (data) => {
  const url = $globalRequestUrl({
    url: '/user/chat/delete',
  });
  return await request({
    url,
    method: 'post',
    data
  })
}
const postEditChatImage = async (data) => {
  const url = $globalRequestUrl({
    url: '/user/chat/edit',
  });
  return await request({
    url,
    method: 'post',
    data
  })
}
// 模型list
const getChatModelList = async () => {
  const url = $globalRequestUrl({
    url: '/mould',
  });
  return await request({
    url,
    method: 'get',
  })
}
// 模型选择
const postChatModelSelect = async (data) => {
  const url = $globalRequestUrl({
    url: '/user/chat/update/mould',
  });
  return await request({
    url,
    method: 'post',
    data
  })
}
const getChatPostMessageUrl = async() => {
  const url = $globalRequestUrl({
    url: '/random/url',
  });
  return await request({
    url,
    method: 'get',
  })
}
const getNewGoodsUrl = async() => {
  const url = $globalRequestUrl({
    url: '/new/goods',
  });
  return await request({
    url,
    method: 'get',
  })
}

export { getChatList, getPersonChatList, postCreateRole, postEditRole, handleSetDefaultRole, getChatDetail, getTemplateList, setDefalutTemplate, deleteRole, deleteChat, postChatMessage, saveChatMessage, deleteChatMessage, editChatMessage, batchDeleteChatMessage, createChat, getRoleDetails, postEditChatImage, getChatModelList, postChatModelSelect, getChatPostMessageUrl, getNewGoodsUrl };
